package com.bruip.intercepltor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 拦截器的三个方法;
 * 1. preHandle():在控制器方法执行之前执行，其返回值表示对控制器方法的拦截（false）和放行（true）
 * 2. postHandle():在控制器方法执行之后执行
 * 3. afterCompletion():在控制器方法执行之后，且渲染视图完毕之后执行
 *
 * @author 王若龙
 * @CreateTime 2022-09-07 15:29
 */
@Component
public class SecondInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("SecondInterceptor --> preHandle");
        return HandlerInterceptor.super.preHandle(request, response, handler);
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("SecondInterceptor --> postHandle");
//        HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("SecondInterceptor --> afterCompletion");
//        HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
    }
}
